;; -*- coding: utf-8 -*-
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))

;; Various preferences
(setq org-log-done t
      org-completion-use-ido t
      org-edit-timestamp-down-means-later t
      org-agenda-start-on-weekday nil
      org-agenda-ndays 14
      org-agenda-include-diary t
      org-agenda-window-setup 'current-window
      org-fast-tag-selection-single-key 'expert
      org-tags-column 80)


; Refile targets include this file and any file contributing to the agenda - up to 5 levels deep
(setq org-refile-targets (quote ((nil :maxlevel . 5) (org-agenda-files :maxlevel . 5))))
; Targets start with the file name - allows creating level 1 tasks
(setq org-refile-use-outline-path (quote file))
; Targets complete in steps so we start with filename, TAB shows the next level of targets etc
(setq org-outline-path-complete-in-steps t)

(setq org-todo-keywords
      '((sequence "PENDING(p)" "WAIT(w)" "TODO(t)" "DOING(i)"  "|" "CANCEL(l)" "DONE(d)")
        (sequence "OPEN(o)" "|" "CLODED(c)")))

;; Save the running clock and all clock history when exiting Emacs, load it on startup
(setq org-clock-persistence-insinuate t)
(setq org-clock-persist t)
(setq org-clock-in-resume t)

;; Change task state to STARTED when clocking in
(setq org-clock-in-switch-to-state "STARTED")
;; Save clock data and notes in the LOGBOOK drawer
(setq org-clock-into-drawer t)
;; Removes clocked tasks with 0:00 duration
(setq org-clock-out-remove-zero-time-clocks t)

(setq org-agenda-files 
      (list "~/org/personal.org"
            "~/org/memory.org"
            "~/org/wait.org"
            "~/org/sched.org"
            "~/org/action.org"
            "~/org/project.org"))

(defun gtd ()
  (interactive)
  (find-file "~/org/personal.org")
  (find-file "~/org/memory.org")
  (find-file "~/org/wait.org")
  (find-file "~/org/sched.org")
  (find-file "~/org/project.org")
  (find-file "~/org/action.org"))

(eval-after-load 'org
  '(progn
     (require 'org-exp)
     (require 'org-clock)
     ;; (require 'org-checklist)
     ;; (require 'org-fstree)
     ))


(provide 'init-org)
